import { getEntireListData } from '@/servers/modules/entire'
import * as actionTypes from './constants'

export function changeCurrentPageAction(currentPage) {
	return {
		type: actionTypes.CHANGE_CURRENT_PAGE,
		currentPage
	}
}

export function changeRoomListAction(roomList) {
	return {
		type: actionTypes.CHANGE_ROOM_LIST,
		roomList
	}
}

export function changeTotalCountAction(totalCount) {
	return {
		type: actionTypes.CHANGE_TOTAL_COUNT,
		totalCount
	}
}

export function changeIsLoadingAction(isLoading) {
	return {
		type: actionTypes.CHANGE_IS_LOADING,
		isLoading
	}
}

export function fetchEntireDataAction(page = 0) {
	return async dispatch => {
		dispatch(changeIsLoadingAction(true))
		dispatch(changeCurrentPageAction(page))

		const offset = page * 20
		const res = await getEntireListData(offset)
		dispatch(changeRoomListAction(res.list))
		dispatch(changeTotalCountAction(res.totalCount))

		dispatch(changeIsLoadingAction(false))
	}
}
